package com.riven.bilibilidemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.riven.bilibilidemo.R;
import com.riven.bilibilidemo.bean.TopicCenterBean;
import com.riven.bilibilidemo.utils.UIUtils;

import java.util.List;

/**
 * 用途:话题中心适配器
 * 制作者:ZhangQi.
 * 创建时间:2017/3/10 20:02
 * 邮箱号:m15010535154@163.com
 */

public class MyRvTopicCenterAdapter extends RecyclerView.Adapter<MyRvTopicCenterAdapter.MyViewHodler>{

    private Context context;
    private List<TopicCenterBean.ListBean> topicList;
    private View mView;
    public MyRvTopicCenterAdapter(Context context, List<TopicCenterBean.ListBean> topicList) {

        this.context = context;
        this.topicList = topicList;
    }

    @Override
    public MyViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_topic_center,null);
        return new MyViewHodler(view);
    }

    @Override
    public void onBindViewHolder(MyViewHodler holder, final int position) {
        holder.tv_title.setText(topicList.get(position).getTitle());
        UIUtils.loadImage(topicList.get(position).getCover(),holder.iv_cover);

        mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UIUtils.getToast("我点击了"+position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return topicList.size();
    }

    public class MyViewHodler extends RecyclerView.ViewHolder {

          ImageView iv_cover;
          TextView tv_title;

        public MyViewHodler(View itemView) {
            super(itemView);
            mView = itemView;
            iv_cover = (ImageView) itemView.findViewById(R.id.iv_cover);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title);

        }
    }
}
